package com.lt.exam.mubanfangfa.ShiXian;

import com.lt.exam.ZhuangShiQi.BingLi;
import com.lt.exam.ZhuangShiQi.ShiXian.*;
import com.lt.exam.mubanfangfa.YiYuan;
import com.lt.exam.zhuhemoshi.Composite;
import com.lt.exam.bingren.BingRen;
import com.lt.exam.zhuhemoshi.ShiXian.*;
import com.lt.exam.zhuhemoshi.SuoYouYiYuanChuShiHua;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * @author LT
 * @version 1.0
 * @PackageName com.lt.exam.mubanfangfa
 * @ClassName OneYiYuan
 * @Description to do
 * @date 2021/11/30 11:56
 */
public class OneYiYuan extends YiYuan {
    //存放病人
    private BingRen bingren;
    //输入字符流
    BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
    //医院组织结构
    Composite c = new SuoYouYiYuanChuShiHua().getOneYiYuan();

    @Override
    public void guaHao() {
        System.out.println("一医院为您服务。。。");
        bingren = new BingRen();
        System.out.println("请输入您的姓名");
        try {
            bingren.setName(rd.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("一医院的结构为：请按照以下信息来挂号");
        c.print();
        String yiShengName;
        boolean flag = false;
        do {
            try {
                System.out.println("\n请输入医生姓名");
                yiShengName = (String) rd.readLine();
                switch (yiShengName) {
                    case "1医生":
                        bingren.setYiShengName(yiShengName);
                        bingren.setBuMenName("消化内科");
                        bingren.setYisheng(new OneYiSheng("1医生"));
                        flag = true;
                        break;
                    case "2医生":
                        bingren.setYiShengName(yiShengName);
                        bingren.setBuMenName("消化内科");
                        bingren.setYisheng(new TwoYiSheng("2医生"));
                        flag = true;
                        break;
                    case "3医生":
                        bingren.setYiShengName(yiShengName);
                        bingren.setBuMenName("心血管科");
                        bingren.setYisheng(new ThreeYiSheng("3医生"));
                        flag = true;
                        break;
                    case "4医生":
                        bingren.setYiShengName(yiShengName);
                        bingren.setBuMenName("骨科");
                        bingren.setYisheng(new FourYiSheng("4医生"));
                        flag = true;
                        break;
                    case "5医生":
                        bingren.setYiShengName(yiShengName);
                        bingren.setBuMenName("神经外科");
                        bingren.setYisheng(new FiveYiSheng("5医生"));
                        flag = true;
                        break;
                    default:
                        System.out.println("医生名字输入错误，请重试");
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        } while (!flag);

        BingLi bingLi = new JiBenBingLi();
        bingLi = new GuaHao(bingLi);
        bingren.setBingLi(bingLi);
        System.out.println("请缴纳挂号费 " + bingLi.cost() + "元");
        double money = 0.0;
        while (money != bingLi.cost()){
            try {
                money = Double.parseDouble(rd.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (money > bingLi.cost()) {
                System.out.println("缴费成功，找零 " + (money-bingLi.cost()) + "元");
                break;
            }else if(money < bingLi.cost()){
                System.out.println("金额不足,请缴纳挂号费用 " + bingLi.cost() + "元");
            }else{
                System.out.println("缴费成功");
            }
        }
        System.out.println("挂号缴费成功");
        System.out.println("以下是您的挂号信息"+ bingren.toString());
        System.out.println("您已经挂上了" + bingren.getYiShengName() + "的号，请去诊断室等待...");
        }

        @Override
        public void queZheng () {
            System.out.println("\n"+bingren.getYiShengName() + "给您看病..........，修改病例，开药");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            BingLi bingLi = bingren.getYisheng().XiuGaiBingLi();
            bingren.setBingLi(bingLi);
            System.out.println("病例已经修改完成，请去大厅缴费......");
        }

        @Override
        public void fuFei () {
            BingLi bingLi = bingren.getBingLi();
            double money = 0.0;
            System.out.println("\n以下是您的信息"+ bingren.toString());
            System.out.println("病例内容 "+bingLi.getDescription());
            System.out.println("请缴纳病例费用 " + bingLi.cost() + "元");
            while (money != bingLi.cost()){
                try {
                    money = Double.parseDouble(rd.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (money > bingLi.cost()) {
                    System.out.println("缴费成功，找零 " + (money-bingLi.cost()) + "元");
                    break;
                }else if(money < bingLi.cost()){
                    System.out.println("金额不足,请缴纳病例费用 " + bingLi.cost() + "元");
                }else{
                    System.out.println("缴费成功");
                }
            }
            System.out.println("病例费用缴费成功");
            System.out.println("请去药房取药，然后去诊断室等待医生说明");
        }

        @Override
        public void zhiLiao () {
            BingLi bingLi = bingren.getBingLi();
            System.out.println("\n医生讲述"+bingLi.getDescription()+"的使用方法");
            System.out.println("医生正在为您治疗。。。。。。。。。。。。。。。。。。。。");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("医生询问是否拿齐需要的药物，药物清单为："+bingren.getBingLi().getDescription());
            System.out.println("请确认是否药物拿完了 1拿完 2没拿完");
            int i = 0;
            do {
                try {
                    i = Integer.parseInt(rd.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                switch (i) {
                    case 1:
                        System.out.println("取药完成");
                        break;
                    case 2:
                        System.out.println("取走未拿走的药物");
                        break;
                    default:
                        System.out.println("操作输入错误，请重试");
                }
            }while(i!=1);
            System.out.println("请按照医生说明按时吃药！");
        }

        @Override
        public void jieShuZhiLiao () {
            bingren = null;
            System.out.println("\n完成看病全部过程，看病结束，祝您身体健康！");
            try {
                rd.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
